package zwp.exercise.demo_exercise.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import zwp.exercise.demo_exercise.mapper.MySqlTestMapper;
import zwp.exercise.demo_exercise.pojo.domain.HolidayDomain;
import zwp.exercise.demo_exercise.service.MySqlTestService;

import java.util.List;

/**
 * @Author zwp14
 * @create 2024/6/10 20:38
 * @description 业务实现
 */
@Service
@RequiredArgsConstructor
public class MySqlTestServiceImpl implements MySqlTestService {

    /**
     * 测试DAO
     */
    private final MySqlTestMapper mySqlTestMapper;

    /**
     * 数据库连接测试
     * @return 数据
     */
    @Override
    public String connectTest1() {
        HolidayDomain holidayDomain = mySqlTestMapper.connectTest1();
        return JSONObject.toJSONString(holidayDomain);
    }

    /**
     * 使用mybatis-plus查询数据库
     * @return 查询结果
     */
    @Override
    public List<HolidayDomain> connectTest2() {
        LambdaQueryWrapper<HolidayDomain> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(HolidayDomain::getDateType,"1");
        return mySqlTestMapper.selectList(queryWrapper);
    }
}
